home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / 3dvect37.zip / XMOUSE.ASM < prev    next >
Assembly Source File  |  1994-06-22  |  6KB  |  208 lines

  1. ; if the mouse appears to flash, it's not a bug!!!    the  routine  is designed
  2. ; to remember only one page of data and is to be used for things like selection
  3. ; of menu items and such. it is not intended to be used during an animation.
  4.  
  5.          .386p
  6.          jumps
  7.  
  8. code32   segment para public use32
  9.          assume cs:code32, ds:code32
  10.  
  11.          include pmode.ext       ; protected mode externals
  12.          include xmode.ext       ; include externals for xmode routines
  13.          include macros.inc
  14.          include equ.inc
  15.  
  16.          public show_mouse
  17.          public get_mouse_position
  18.          public plot_mouse
  19.          public instant_mouse
  20.          public remove_mouse
  21.          public mousex
  22.          public mousey
  23.          public mbuttons
  24.  
  25. ; x-mode mouse routines in protected mode for 3d vectors source
  26. ;
  27. ; show_mouse (int x, int y)
  28. ; get_mouse_position
  29. ; plot_mouse
  30. ; remove_mouse
  31. ; instant_mouse
  32. ;
  33. ; after ploting mouse, sync_display is called to avoid flickering
  34.  
  35. mousewidth  equ 9
  36. mouseheight equ 9
  37.  
  38. ismouse  db -1
  39.  
  40. mc = 208 ; mouse colour block (cyan)
  41.  
  42. mousemap:
  43.  dw mousewidth,mouseheight  ; 9x9 mouse
  44.  
  45.  db mc+12,mc+12,mc+12,mc+12,mc+12,mc+12,mc+12,mc+12, 0  ; hmmm, I wonder  where
  46.  db mc+02,mc+10,mc+11,mc+11,mc+11,mc+11,mc+05,    0, 0  ; this mouse image came
  47.  db mc+01,mc+08,mc+11,mc+11,mc+11,mc+06,    0,    0, 0  ; from?...sorry guys..
  48.  db mc+00,mc+07,mc+11,mc+11,mc+11,mc+11,mc+12,    0, 0
  49.  db mc+00,mc+05,mc+11,mc+06,mc+11,mc+11,mc+11,mc+12, 0
  50.  db mc+00,mc+04,mc+03,mc+00,mc+03,mc+11,mc+11,mc+11,mc+12
  51.  db mc+00,mc+02,mc+00,    0,mc+00,mc+03,mc+09,mc+05,mc+01
  52.  db mc+00,mc+00,    0,    0,    0,mc+00,mc+03,mc+01, 0
  53.  db     0,    0,    0,    0,    0,    0,mc+00,    0, 0
  54.  
  55. ;mousemap:
  56. ;         dw mousewidth,mouseheight
  57. ;         db 9,9,9,9,9,0 ; simple 6x6 mouse
  58. ;         db 9,9,9,9,0,0
  59. ;         db 9,9,9,9,0,0
  60. ;         db 9,9,9,9,9,0
  61. ;         db 9,0,0,9,9,9
  62. ;         db 0,0,0,0,9,0
  63.  
  64. sm_stack  struc
  65.                 dd  ?   ; ebp
  66.                 dd  ?   ; caller
  67.     setm_ypos   dw  ?   ; y pos of mouse
  68.     setm_xpos   dw  ?   ; x pos of mouse
  69. sm_stack  ends
  70.  
  71. show_mouse:
  72.         push ebp
  73.         call remove_mouse
  74.         mov v86r_ax,0                   ; enable mouse
  75.         mov al,33h
  76.         int 33h
  77.         mov ah,v86r_ah                  ; check if hardware/driver installed
  78.         xor ah,255
  79.         mov ismouse, ah
  80.         jne sm_nomouse                  ; no mouse, exit
  81.  
  82.         mov ebp, esp                    ; set up stack frame
  83.         mov cx, [ebp].setm_xpos
  84.         mov dx, [ebp].setm_ypos
  85.  
  86.         mov v86r_ax,4                   ; position mouse
  87.         mov v86r_cx,cx
  88.         mov v86r_dx,dx
  89.         int 33h
  90.  
  91.         mov v86r_ax,7                   ; set screen size
  92.         mov v86r_cx,0
  93.         mov v86r_dx,(xactual-mousewidth)*2
  94.         int 33h                         ; *2 gives greater resolution!!!!!
  95.  
  96.         mov v86r_ax,8
  97.         mov v86r_cx,0
  98.         mov v86r_dx,(yactual-mouseheight)*2
  99.         int 33h
  100.  
  101.         mov v86r_ax,15                  ; set mouse mickeys (8 = default)
  102.         mov v86r_cx,8
  103.         mov v86r_dx,8
  104.         int 33h
  105.  
  106. sm_nomouse:
  107.         mov firstcall,0                 ; first call to mouse routines, reset
  108.         pop ebp
  109.         ret 4
  110.  
  111. get_mouse_position:
  112.         cmp ismouse,0
  113.         jne gm_nomouse
  114.         mov v86r_ax,3                   ; call bios routines
  115.         mov al,33h
  116.         int 33h
  117.         mov bx,v86r_bx                  ; button status, mid right left=%111
  118.         mov cx,v86r_cx                  ; coloum
  119.         mov dx,v86r_dx                  ; row
  120.         mov mbuttons,bx                 ; save button status
  121.         shr cx,1                        ; compensate for resolution!!!
  122.         shr dx,1
  123.         mov mousex,cx
  124.         mov mousey,dx
  125. gm_nomouse:
  126.         ret
  127.  
  128. ; plot mouse at new location. must be called often because DOS fuctions cannot
  129. ; plot new mouse in x-mode and protected mode cannot handle re-routing of
  130. ; interrupt.  routine is slow but we must wait for a vga sync anyway.
  131.  
  132. savedmap  dw mousewidth,mouseheight
  133.           db mousewidth*mouseheight dup (?)
  134. mousex    dw 0
  135. mousey    dw 0
  136. mbuttons  dw 0
  137. firstcall db 0
  138.  
  139. plot_mouse:
  140.         cmp ismouse,0                   ; plot mouse may need modification
  141.         jne pm_nomouse                  ; if used with page flipping, (save
  142.                                         ; more than one page)
  143.         call remove_mouse
  144.         mov firstcall,1
  145.  
  146.         call get_mouse_position         ; get new mouse location
  147.  
  148.         mov bx, mouseheight             ; counters
  149.         mov ax, mousewidth
  150.         mov esi, 4                      ; indexer to bitmap saved data
  151.  
  152. pl_morew:                               ; save data under new cursor
  153.         pusha
  154.         push cx dx
  155.         call read_point
  156.         mov b savedmap[esi],al
  157.         popa
  158.         inc si
  159.         inc cx
  160.         dec ax
  161.         cmp ax,0
  162.         jne pl_morew
  163.  
  164.         inc dx
  165.         mov cx,mousex
  166.         mov ax,mousewidth
  167.         dec bx
  168.         cmp bx,0
  169.         jne pl_morew
  170.  
  171.         push o mousemap
  172.         pushw mousex
  173.         pushw mousey
  174.         call tdraw_bitmap               ; draw new mouse
  175. pm_nomouse:
  176.         call sync_display
  177.         ret
  178.  
  179. instant_mouse:
  180.         cmp ismouse,0
  181.         jne im_nomouse
  182.  
  183.         call get_mouse_position         ; get new mouse location
  184.  
  185.         push o mousemap
  186.         pushw mousex
  187.         pushw mousey
  188.         call tdraw_bitmap               ; draw new mouse
  189. im_nomouse:
  190.         ret
  191.  
  192. remove_mouse:
  193.         cmp firstcall,0                 ; check if mouse on screen
  194.         je  pl_dontsave
  195.  
  196.         push o savedmap
  197.         pushw mousex
  198.         pushw mousey
  199.         call draw_bitmap                ; restore old data under cursor
  200.         mov firstcall,0                 ; mouse is gone, say so
  201.  
  202. pl_dontsave:
  203.         ret
  204.  
  205. code32  ends
  206.         end
  207.  
  208.